package com.mentaleye.controller;

import com.alibaba.fastjson.JSONObject;
import com.mentaleye.biz.DeployBiz;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"/activiti"})
public class DeployController
{

  @Autowired
  DeployBiz deployBiz;

  @RequestMapping({"/deployList"})
  public ModelAndView deployList()
  {
    ModelAndView view = new ModelAndView("cm/activiti/deploy/deployList");

    return view;
  }
  @RequestMapping({"/deployListData"})
  @ResponseBody
  public String autoFormListData(CommonPage commonPage) {
    this.deployBiz.getProcessDefinitionListPage(commonPage);
    return commonPage.toSHowPage();
  }

  @RequestMapping({"/deployFile"})
  @ResponseBody
  public String importPicFile1(@RequestParam("uploadFileName") MultipartFile myfile) {
    return JSONObject.toJSONString(new CommonResult(Boolean.valueOf(this.deployBiz.deployFile(myfile))));
  }

  @RequestMapping({"/changeStatus"})
  @ResponseBody
  public String changeStatus(@RequestParam("processDefinitionId") String processDefinitionId, @RequestParam("active") boolean active)
  {
    return JSONObject.toJSONString(new CommonResult(Boolean.valueOf(this.deployBiz.activateOrSuspendProcessDefinition(processDefinitionId, active))));
  }

  @RequestMapping({"/deleteDeploy"})
  @ResponseBody
  public String deleteDeploy(@RequestParam("deploymentId") String deploymentId) {
    return JSONObject.toJSONString(new CommonResult(Boolean.valueOf(this.deployBiz.deleteDeploy(deploymentId))));
  }
}